home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / js.zip / AMEND.JS next >
Text File  |  1992-12-30  |  3KB  |  83 lines

  1.    NB.  This file can be used as a script input file to J Version 6.1
  2.    NB.  December 1992
  3.    
  4.    NB.  Donald B. McIntyre
  5.    NB.  Luachmhor, 1 Church Road
  6.    NB.  KINFAUNS, PERTH PH2 7LD
  7.    NB.  SCOTLAND - U.K.
  8.    NB.  Telephone:  In the UK:      0738-86-726
  9.    NB.  From USA and Canada:   011-1-738-86-726
  10.    NB.  email:  donald.mcintyre@almac.co.uk
  11.  
  12.  
  13. NB. "Using J's Boxed Arrays", VECTOR Vol.9 #1 (July 1992) 92-105
  14. NB.  AMENDMENT: "A Change for the Better", VECTOR.   In Press
  15.  
  16. NB. simulate the 5 by 6 array of nested cells:
  17.    ]d=.<"0 i.5 6
  18. NB. The numbers can be called "linear indexes"
  19.    li=. [ { i.@$@]     NB. Fork
  20. NB. The linear indices of rows 1 and 4 are:
  21.    1 4 li d
  22. NB. The linear index of the cell at row 2 and column 5:
  23.    (<2 5) li d
  24.  
  25. NB. To place the array x in this cell:
  26.    x=. < 9 8 7 6,:5 4 3 2
  27.    x 17} d
  28.  
  29. NB. Scattered indexing:
  30.    (x;'London') ((2 5; 4 2) li d)} d
  31. NB. Expand the table and amend new rows 1 and 4:
  32.    exp=. /:@\:@[ { #@[{.]
  33.    e=. 1 0 1 1 0 1 1 exp d
  34.    t=. e (1 li d)}~ 'Bob';'Bernecky';'Toronto';35;22000; 4 5
  35.    t (4 li d)}~ 'Graham';'Woyka';'U.K.';62;35000;14 31 5 7
  36.    
  37. y=. ('Graham';'Woyka';'U.K.';1;2;3),:'Vin';'Grannell';'Los Angeles';4;5;6 7 8
  38.    ]z=. e (1 4 li e)}~ 1 0{ y
  39.  
  40. NB. Alternatively:
  41.       v=. 1 4&li
  42.       v e
  43.       u=. v@]}
  44.       z-: e u~ 1 0{y
  45. NB. ----------------------------------------------------
  46. NB. "Mastering J",  APL91, APL Quote Quad 21#4 (Aug 91) p.264-273
  47. NB. "Jacobi's method for Eigenvalues: an Illustration of J",
  48. NB.  VECTOR, In Press
  49.  
  50. NB. Capitalize the first occurrence of each vowel:
  51.       s=. 'now is the time for all of us'
  52.       i=. s i. 'aeiou'
  53.       x=. 'AEIOU'
  54.       x i}s
  55.  
  56. NB.   x i} m  Amend was amended in Version 4.
  57. NB.  Illustrations from Jacobi's method
  58.  
  59.    m=. i.6 6
  60.    ]i=. 2 2; 2 4; 4 2; 4 4
  61.    x=. 100 101 102 103
  62.    f=. >@[ +/ .* ,&1@#@]
  63.    i f m
  64.    x (i f m)}m
  65.    
  66.    ut=. ,@(</~@i.)@#            NB.  Upper Triangle
  67.    pt=. (, i. >./@(ut # ,))@|   NB.  Pivot in Triangle
  68.    pm=. <.@(pt % #) , # | pt    NB.  Pivot in Matrix
  69.    pa=. 0 0&{ ; ] ; |. ; 1 1&{  NB.  Permutations for amend
  70.    ia=. pa@pm { i.@$            NB.  Indices for Amend
  71.    amend=. ia@]}                NB.  Amend the right argument
  72.  
  73.    qrl=. 9!:0                NB. Query Random Link:  qrl 0
  74.    setrl=. 9!:1              NB. Set Random Link:  setrl 7^5
  75.    setrl 7^5
  76.    ]y=. 50-~ ?6 6$100
  77.    x amend y
  78.    
  79.    p=.  0 0&{ ; ] ; |. ; 1 1&{   NB.  permutations for amend
  80.    ia=. p@pm { i.@$              NB.  indices for amend
  81.    id=. =/~ i.6
  82.    x (ia y)} id
  83.